package com.example.healthsystem.service.impl;

import com.example.healthsystem.entity.*;
import com.example.healthsystem.exception.PersistenceException;
import com.example.healthsystem.mapper.ReglistMapper;
import com.example.healthsystem.service.ReglistService;
import com.example.healthsystem.util.HashUtils;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

import java.sql.Timestamp;
import java.util.List;

@Service
public class ReglistServiceImpl implements ReglistService {
    @Autowired
    ReglistMapper reglistMapper;

    @Override
    public void insertList(reglist reglist){
        if(reglistMapper.insertList(reglist)==0){
            throw new PersistenceException("无法插入该注册表");
        }
    }

    @Override
    public void deleteList(String name){
        if(reglistMapper.deleteList(name)==0){
            throw new PersistenceException("无法删除这条数据");
        }
    }

    @Override
    public void changeList(String name,int unregnum,Timestamp lastregtime){
        if(reglistMapper.changeList(name,unregnum,lastregtime)==0){
            throw new PersistenceException("无法对这条数据进行更新");
        }
    }

    @Override
    public reglist searchNameList(String name){
        return reglistMapper.searchNameList(name);
    }

    @Override
    public List<reglist> searchAllList(int pageNum,int pageSize){
        PageHelper.startPage(pageNum, pageSize);

        return reglistMapper.searchAllList();
    }
}
